<template>
  <div>
    <table-data ref="table" :config="table_config" :searchFormConfig="search_form_config">
    </table-data>
  </div>
</template>

<script>
import TableData from "@c/tableData"
import {OrderWait,OrderOvertime,OrderOver,OrderCancel,OrderReturn } from "@/api/order.js"


export default {
  name: "Order",
  components: {
    TableData
  },
  data() {
    return {
      form: {
        brand: "",
        type: ""
      },
      options: [],
      table_config: {
        thead:[
          {label:"订单号",prop:"order_no"},
          {label:"状态",prop:"order_status",type:"function",callback:(row)=> {
            return this.$store.state.config.order_status[row.order_status].label;
          }},
          {label:"订单日期",prop:"subscribe_cars_date"},
          {label:"车牌号",prop:"carsNumber"},
          {
            label:"操作",
            type: "operation",
            width: 500,
            buttonGroup: [
              {event:"link",label:"编辑",type:"primary",name:"MemberInfo",key:"id",value:"memberId"},
              {event:"button",label:"待取车",type:"primary",handler:(data)=>this.orderWait(data)},
              {event:"button",label:"超时",type:"primary",handler:(data)=>this.orderOvertime(data)},
              {event:"button",label:"完成",type:"primary",handler:(data)=>this.orderOver(data)},
              {event:"button",label:"取消",type:"primary",handler:(data)=>this.orderCancel(data)},
              {event:"button",label:"待还车",type:"primary",handler:(data)=>this.orderReturn(data)},
            ],
            default: {
              // deleteBtn: true,
              // deleteKey: "memberId"
            },
            slotName: "operation"
          },
        ],
        url: "orderList",
        data: {
          pageSize: 10,
          pageNumber: 1
        }
      },
      search_form_config: {
        form_item: [
          {label:"关键字",type:"Keyword",options:["username","truename","card_id"]}
        ],
      },
    }
  },
  methods: {
    handleReload() {
      this.$refs.table.requestData();
    },
    orderWait(data) {
      OrderWait({
        order_no: data.order_no,
        cars_id: data.cars_id
      }).then((res) => {
        this.handleReload();
      })
    },
    orderOvertime(data) {
      OrderOvertime({
        order_no: data.order_no,
        cars_id: data.cars_id
      }).then((res) => {
        this.handleReload();
      })
    },
    orderOver(data) {
      OrderOver({
        order_no: data.order_no,
        cars_id: data.cars_id
      }).then((res) => {
        this.handleReload();
      })
    },
    orderCancel(data) {
      OrderCancel({
        order_no: data.order_no,
        cars_id: data.cars_id
      }).then((res) => {
        this.handleReload();
      })
    },
    orderReturn(data) {
      OrderReturn({
        order_no: data.order_no,
        cars_id: data.cars_id
      }).then((res) => {
        this.handleReload();
      })
    },
  }
}
</script>

<style lang="scss" scoped>

</style>